package com.gzx.risk.app.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.gzx.spring.db.service.OrderReviewService;
import com.gzx.spring.db.service.PhoneProductOrderService;

import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;

@Controller
@RequestMapping("/api/info")
@Slf4j
public class CreditReviewController {
	@Resource
	private OrderReviewService orderReviewService;

	@Resource
	private PhoneProductOrderService phoneProductOrderService;

	@GetMapping("/list")
	public String list(Model model) {
		model.addAttribute("orders", orderReviewService.getOrders());
		return "list";
	}

	@GetMapping("/detail")
	public String detail(Model model, @RequestParam(name = "ordercode", required = true) String ordercode) {
		model.addAttribute("order", orderReviewService.getOrder(ordercode));
		return "detail";
	}

	@PostMapping("/reject")
	public String reject(@RequestParam(name = "ordercode", required = true) String ordercode) {
		log.info("reject ordercode:{}", ordercode);

		orderReviewService.reject(ordercode);
		return "list";
	}

	@PostMapping("/permit")
	public String permit(@RequestParam(name = "ordercode", required = true) String ordercode) {
		log.info("permit ordercode:{}", ordercode);
		orderReviewService.permit(ordercode);
		return "list";
	}
}
